﻿@model Tasks.UI.Models.Power.RoleManageModel
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <link href="@Config.GetCssResourcePath("main.css")" rel="stylesheet" type="text/css" />
    <link href="@Config.GetCssResourcePath("table.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery-impromptu.3.1.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/global.js")" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {

        })
        //1 编辑 0 常态
        function setRowState(src, state) {
            var row = $(src).parent().parent();
            var infos = $(".info", row);
            infos.each(function (i) {
                //alert($(this).text());
                if (state == 1) {
                    var ipt = document.createElement("input");
                    ipt.name = $(this).attr("name");
                    ipt.type = "text";
                    ipt.className = "txt";
                    ipt.value = $.trim($(this).text());
                    $(this).text("");
                    $(this).attr("originText", ipt.value); //设置文本框原始值
                    $(this).append(ipt);
                }
                else if (state == 0) {
                    var originText = $(this).attr("originText");
                    $(this).text(originText);

                    if (originText == undefined || originText == "") {
                        row.remove();
                    }
                } else if (state == 2) {
                    $(this).text($(this).children().val());
                }
            });

            if (state == 1) {
                $(".btnEdit", row).hide();
                $(".btnCanelEdit", row).show();
                $(".btnSaveRow", row).show();
                $(".delRow", row).hide();
                $(".showAssign", row).hide();
            }
            else if (state == 0) {
                $(".showAssign", row).show();
                $(".btnEdit", row).show();
                $(".btnCanelEdit", row).hide();
                $(".btnSaveRow", row).hide();
                $(".delRow", row).show();

            } else {
                $(".btnEdit", row).show();
                $(".btnCanelEdit", row).hide();
                $(".btnSaveRow", row).hide();
                $(".delRow", row).show();
                $(".showAssign", row).show();
            }
        }
        function editRow(src) {
            setRowState(src, 1);
        }
        function addRow() {
            var tr = $("#tb tr").eq(1).clone();
            tr.show();
            tr.appendTo("#tb");

            setDialogHeight();
        }

        function saveRow(src) {
            var objRow = $(src).parent().parent();
            var objInputs = $("input", objRow);
            var parm = objInputs.serialize();
            var RoleName = objInputs.eq(0).val();
            var dspt = objInputs.eq(1).val();
            if (RoleName != "" && dspt != "") {
                $.ajax({
                    url: "/Power/DoEditRoleInfo",
                    type: "post",
                    dataType: "json",
                    data: parm,
                    completed: function () { alert("complete") },
                    success: function (RoleID) {
                        if (RoleID == 0) {
                            $.Msg.alert("", "保存失败!", 2000);
                        }
                        else {
                            $("input:hidden", objRow).val(RoleID);
                            $.Msg.alert("", "保存成功!", 2000);
                            setRowState(src, 2);
                        }
                    }
                });
                
            }
            else {
                $.Msg.alert("", "请正确输入信息!", 2000);
            }
        }
        function delRow(src) {
            $.Msg.confirmDelete(
            function () {
                var objRow = $(src).parent().parent();
                var objInputs = $("input", objRow);
                var parm = objInputs.serialize();
                $.ajax({
                    url: "/Power/DoDeleteRole",
                    type: "post",
                    dataType: "json",
                    data: parm,
                    completed: function () { alert("complete") }
                });
                setRowState(src, 0);
                objRow.remove();

            }
        );
        }
        function showDict(title, src) {
            var objRow = $(src).parent();
            var roleID = $(".RoleID", objRow).val();
            var url = "/Power/AssignRolePower?RoleId=" + roleID;
            parent.addTab2({ name: '分配权限', url: url, showHead: false, template: 1, refresh: false, isModal: true })
        }
        function menuPower(src) {
            var objRow = $(src).parent();
            var roleID = $(".RoleID", objRow).val();
            var url = "/Power/MenuRolePower?RoleId=" + roleID;
            parent.addTab2({ name: '分配菜单', url: url, showHead: false, template: 1, refresh: false, isModal: true })
        }
        function closeDiv() {
            document.getElementById('panel').style.display = 'none';
        }
    </script>
    <style type="text/css">
        .tblStyle1 input
        {
            width: 90%;
        }
    </style>
</head>
<body>
    <form id="form1" method="post" action="RoleManage">
    <div id="container">
        @Html.Hidden("Name")
        <input id="act" name="act" type="hidden" />
        <div class="navTitle">
            <ul>
                <li class="Home SecondLast"><a href="#">
                    <div class="HomeIcon">
                    </div>
                    <font><font>权限</font></font></a></li><li class="Last"><span><font><font>角色管理</font></font></span></li>
            </ul>
        </div>
        <h1>
            <font class="">角色管理</font>
        </h1>
        <p class="intro">
            <font>分配角色需要先创建一个角色名称，再为该角色分配角色具备的权限。在对员工分配角色权限后，该员工就具备指定角色的所有权限，分配多个角色具备多个角色的权限。</font>
        </p>
        <table class="tblStyle1" style="table-layout: fixed; width: 100%;" id="tb">
            <thead>
                <tr>
                    <th style="width: 20%">
                        权限组名称
                    </th>
                    <th style="width: 60%">
                        描述
                    </th>
                    <th style="width: 20%">
                        操作
                    </th>
                </tr>
            </thead>
            <tbody>
                <tr style="display: none;">
                    <td class="info" name="RoleName">
                        <input name="RoleName" type="text" />
                    </td>
                    <td class="info" name="Dspt">
                        <input name="Dspt" type="text" />
                    </td>
                    <td class="c">
                        <input name="RoleID" class="RoleID" type="hidden" value="0" />
                        <a href="javascript:void(0)" onclick="editRow(this)" class="btnEdit" style="display: none">
                            <img src="/images/icon/16x16/file_edit.png" title="编辑" /></a> <a href="javascript:void(0)"
                                onclick="setRowState(this,0)" class="btnCanelEdit">
                                <img src="/images/icon/16x16/cancel.png" title="取消" /></a> <a href="javascript:void(0)"
                                    onclick="delRow(this)" class="delRow" style="display: none">
                                    <img src="/images/icon/16x16/delete.png" title="删除" /></a><a href="javascript:void(0)"
                                        onclick="saveRow(this)" class="btnSaveRow"><img src="/images/icon/16x16/save.png"
                                            title="保存" /></a>&nbsp;<a href="javascript:void(0)" onclick="showDict('分配权限',this)"
                                                class="showAssign" style="display: none"><img src="/images/icon/16x16/group_key.png"
                                                    title="授权" /></a>
                    </td>
                </tr>
                @foreach (PowerRole role in Model.PowerRoles)
                {
                    if (role.IsPersonal == 1)
                    {
                        continue;
                    }
                    <tr id="tpl">
                        <td class="info" name="RoleName">
                            @role.Name
                        </td>
                        <td class="info" name="Dspt">
                            @role.Dspt
                        </td>
                        <td class="c">
                            <input name="RoleID" class="RoleID" type="hidden" value="@role.RoleID"/>
                            <a href="javascript:void(0)" onclick="editRow(this)" class="btnEdit">
                                <img src="/images/icon/16x16/file_edit.png" title="编辑" /></a> <a href="javascript:void(0)"
                                    onclick="setRowState(this,0)" class="btnCanelEdit" style="display: none">
                                    <img src="/images/icon/16x16/cancel.png" title="取消" /></a> <a href="javascript:void(0)"
                                        onclick="delRow(this)" class="delRow">
                                        <img src="/images/icon/16x16/delete.png" title="删除" /></a><a href="javascript:void(0)"
                                            onclick="saveRow(this)" class="btnSaveRow" style="display: none"><img src="/images/icon/16x16/save.png"
                                                title="保存" /></a> <a href="javascript:void(0)" onclick="showDict('分配权限',this)">
                                                    <img src="/images/icon/16x16/group_key.png" title="授权" /></a>
                        </td>
                    </tr>
                }
            </tbody>
        </table>
        <div class="BottomBtn">
            <a href="javascript:addRow()" class="button blue medium"><span>添加</span></a></div>
    </div>
    </form>
</body>
</html>
